﻿using EasyLinkerSDK.Enum;
using EasyLinkerSDK.Model.Client.Common.ClientError;
using EasyLinkerSDK.Model.Client.Common.Interface;
using EasyLinkerSDK.Model.Server.Common.Interface;
using EasyLinkerSDK.Model.User;
using System;


namespace EasyLinkerSDK.Client.Message
{
    public class ErrorMessageBuilder
    {
        public static ClientError BuildClientError(ClientInfo clientInfo, IServerMessage server, ClientErrorType error)
        {
            if (clientInfo == null)
            {
                return null;
            }
            ClientError request = new ClientError()
            {
                Device = clientInfo.DeviceType,
                Uid = clientInfo.UserId,
                Key = clientInfo.Key,
                ProtocolType = clientInfo.ProtocolType,
                Type = MessageType.Error,
                Action = server.Action,
                MessageId = server.MessageId,
                DeviceId = clientInfo.DeviceId,
                Data = new ClientErrorData()
                {
                    Code = error,
                    Message = error.ToString().ToUpper()
                }
            };
            return request;
        }
    }
}
